#pragma once

#include "fxcc/core/graph/common/pch.h"
#include "fxcc/core/graph/common/ImageMipmap.h"
#include "fxcc/core/graph/opengl3/gliUtils2.h"
#include "fxcc/core/graph/opengl3/Sampler.h"

namespace fxcc
{

	namespace graph
	{
		namespace opengl3
		{

			struct FXCC_API Texture
			{
				unsigned int m_Id;
				unsigned int m_Target;

				void getError() const
				{
					GLenum err = glGetError();
					if (err != GL_NO_ERROR) {
						ztclog::info("OpenGL Error: failed get image");
					}
				};

				Texture(const unsigned int target) :
					m_Target(target)
				{

				}

				void TexImage2D(int target, int level, const fxcc::graph::common::ImageMipmap::MipMapData& levelData) const;

				fxcc::graph::common::ImageMipmap::MipMapData GetImage2D(int target, int level, int nrComponent, int hdr) const;
				
				bool LoadImage(fxcc::graph::common::ImageMipmap::MipMapData& image, int target, int level, int nrComponent, int hdr) const;

				void Mipmap() const;

				void Create();

				void Delete();

				void Active(unsigned int index) const
				{
					ActiveIndex(index);
					Bind();
				}


				void Bind() const;

				void SetSampler(const fxcc::graph::common::SamplerType& sampler);

				void UnBind() const
				{
					glBindTexture(m_Target, 0);
				}
				unsigned int GetTarget() const;

				virtual ~Texture()
				{
					Delete();
				};

				static void ActiveIndex(int index)
				{
					glActiveTexture(GL_TEXTURE0 + index);
				}



			};

		};
	};
};